﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using FortuneHeaven.DAL.Base;
using FortuneHeaven.Entity.GameScore;
using Jzy.Core.Utility;

namespace FortuneHeaven.DAL.GameScore
{
    public class GameScoreDAL : TreasureBaseDAL
    {
        public List<GameScoreInfo> GetList(IEnumerable<int> userIDs)
        {
            string ids = ConvertUtil.ConvertToDbStr(userIDs);
            string sql = "select * from GameScoreInfo where UserID in (" + ids + ")";
            return dbOper.Query<GameScoreInfo>(sql);
        }

        public long GetScoreWithLock(int userID)
        {
            string sql = "select Score from GameScoreInfo where UserID = @p0";
            return dbOper.GetScalar<long>(sql, userID);
        }

        public void UpdateScore(int userID, long score)
        {
            string sql = "update GameScoreInfo set Score=@p1 where UserID=@p0";
            dbOper.RunSql(sql, userID, score);
        }

        public bool InGame(int accountID)
        {
            string sql = "select count(*) from GameScoreLocker where UserID = @p0";
            int count = dbOper.GetScalar<int>(sql, accountID);
            return count > 0;
        }

        public GameScoreInfo GetInfoByUserID(int userID)
        {
            string sql = "select * from GameScoreInfo where UserID=@p0";
            List<GameScoreInfo> lst = dbOper.Query<GameScoreInfo>(sql, userID);
            if (lst.Count > 0)
            {
                return lst.First();
            }
            else
            {
                return null;
            }
        }
    }

}
